﻿<%@ page language="java" contentType="text/html;charset=utf-8"
	pageEncoding="utf-8"%>
	
<%@ page import="com.sms.project.*" %>
<%@ page import="java.util.List, java.util.ArrayList, java.util.Map" %>

<%--
	project/teacher/item-details.jsp
 --%>

<%	//清除内存
	response.setHeader("Pragma","No-cache"); 
	response.setHeader("Cache-Control","no-cache"); 
	response.setDateHeader("Expires", 0); 
%> 


<%
	request.setCharacterEncoding("utf-8");
	String userno = (String)session.getAttribute("userno");
	
	String row = request.getParameter("row");//获取该项目是第几行的参数(从0开始的)
	int num = Integer.parseInt(row);
	Project p = null;

	String progress = request.getParameter("progress");
	String condition = "";
	if(progress != null) {
		if(progress.trim().equals("already")) {
			condition = "finish";
		} else if(progress.trim().equals("unalready")){
			condition = "notfinish";
		} else {
			condition = "";
		}
	} else {
		condition = "";
	}

	//得到该项目的对象并赋值
	List<Project> list = new ArrayList<Project>();
	list = Task.getTProject(userno, condition);
	if(list != null && list.size() > 0) {
		p = (Project)list.get(num);
	} else {
		return;
	}
%>		

 <%
	List<String> member = p.getMember();
	String memberString = "";
	if(member != null) {
		for(int i=0; i<member.size(); i++) {
			String memberName = member.get(i).toString();
			memberString += memberName + ",";
		}
	}
	
	List<String> memberid = p.getMemberID();
	String memberIDString = "";
	if(memberid != null) {
		for(int i=0; i<memberid.size(); i++) {
			String memberID = memberid.get(i).toString();
			memberIDString += memberID + ",";
		}
	}
 %>	


<body>
<div id="project">
<form id="project-details" onSubmit="return false">
<input type="hidden" name="action" value="modify" />
<input type="hidden" name="row" value="<%= row %>" />
<input type="hidden" name="proID" value="<%= p.getProID() %>" />
<input type="hidden" name="grade" value="<%= p.getGrade() %>" />
<input type="hidden" id="leaderID" name="leaderID" value="<%= p.getLeaderID() %>" />
<input type="hidden" name="groupID" value="<%= p.getGroupID() %>" />
<input type="hidden" name="endTime" value="<%= p.getEndTime() %>" />
<input type="hidden" name="memberID" value="<%= memberIDString %>" />

<table cellpadding="0" cellspacing="0">
    <tr><td><label for="name">项目名称:</label></td><td style="text-align:left;height:30px;width:300px;"><%= p.getProName() %></td></tr>
    <tr><td><label for="desc">项目描述:</label></td><td><textarea cols=60 rows=6><%= p.getContent() %></textarea></td></tr>  
    <tr><td><label for="begintime" style="width:110px;">任务开始时间：</label></td><td style="text-align:left;height:30px;width:300px;"><%= p.getStartTime() %></td></tr> 
    <tr><td><label for="deadline" style="width:110px;">任务截止时间：</label></td><td style="text-align:left;height:30px;width:300px;" id="changetime"><%= p.getEndTime() %></td></tr> 
      <tr><td><label for="grade">项目级别：</label></td><td style="text-align:left;" id="changeGrade"><%= (p.getGrade()==2)?"二级模式":"三级模式" %></td></tr>
     <tr><td><label for="header">项目组长：</label></td><td style="text-align:left;height:30px;width:300px;" id="changeLeader"><%= p.getLeaderName() %></td></tr>
      <tr><td id='before'  colspan="2" style="text-align:left;"></td></tr>
      <tr><td><label for="member">项目组员：</label></td><td id="changeMember" style="text-align:left;height:30px;width:300px;"><%= memberString %></td></tr> 
     <% 
     	List<Map> appendFile = null;
		//如果有附件
		if(p.getIsAppend().equals("1")) {
			appendFile = new ArrayList<Map>();
			appendFile = p.getAppendFile();
     %>  
      		<tr class="addfiles"><td><label for="file">附件链接：</label></td>
      		<td style="text-align:left;height:30px;">
      <% 
      		for(int i=0; i<appendFile.size(); i++) {
      				Map<String, String> map = (Map<String, String>)appendFile.get(i);
					String fileName = (String)map.get("fileName");
					String saveName = (String)map.get("saveName");
      %>
      			<a href="DownServlet?fileName=<%= fileName %>&saveName=<%= saveName %>"><%= fileName %></a>&nbsp;&nbsp;
      <%
      		}
      %>
      
      		</td></tr>
      <% }%> 
     <tr><td align="right"><button id="change" style="margin-top:10px; width:100px; height:30px;">修改</button></td>
     <td align="center"><input type="submit" id="save" value="保存修改"  style="margin-top:10px;" /></td></tr>
</table>
</form>
</div>
<script type="text/javascript">
$('#change').click(function(){
	 var inittime=$('#changetime').html();
     var initgrade=$('#changeGrade').html();
     var initleader=$('#changeLeader').html();
     var initLeader=initleader.split("，");
     var initMember=$('#changeMember').html().split("，"); 
	$('#changetime').html("<input name='newEndtime' id='newEndtime'  />");
		$('#newEndtime').datebox({
			okText:'确定',
			formatter:function(date){
				return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
				
				}
			});
		$('#newEndtime').datebox('setValue',inittime);
	$('#before').html('原组员为:'+$('#changeMember').html());	
	$("#changeMember").html("<input name='newMember' id='newMember'  />");
		$('#newMember').combobox({
			url:'GetStudentServlet',    /*添加学员，返回json，注意学员的添加与删除效果测试*/
			valueField:"sno", 
             textField:"sname",
			  height:50,
			 multiple:true,
			 editable:false
			});
		   
    //$('#newMember').combobox('setValue',initMember);	
	
	
	$("#changeLeader").html("<input name='newLeader' id='newLeader' />");
	$('#newLeader').combobox({
			url:'GetStudentServlet',    /*添加学员，返回json，注意学员的添加与删除效果测试*/
			valueField:"sno", 
             textField:"sname",
             dropDownStyle:'csDropDownList',
			 height:50,
			 editable:false
			});
	$('#newLeader').combobox('setValues',initLeader);
		
	if(initgrade=='二级模式'){$('#changeGrade').html("<select name='newGrade' id='newGrade'><option value='2' selected>二级模式</option><option value='3'>三级模式</option></select>");}
	else if(initgrade=='三级模式'){$('#changeGrade').html("<select name='newGrade' id='newGrade'><option value='2'>二级模式</option><option value='3' selected>三级模式</option></select>");}
	})
$("#save").click(function(){
	var grade=$("#newGrade option:selected").attr('value');
	var deadline=$('#newEndtime').datebox('getValue');
	var header=$("#newLeader").combobox('getValue');
	var member=$("#newMember").combobox('getValue');
	var desc=$('textarea').val();
	//alert(member);
	if(grade&&deadline&&header&&member&&desc){
		 $.ajax({
		url:'project/teacher/modify.jsp',                         /*！！！！！后台注意更新处理页面的链接*/
		dataType:'json',
		//data:'grade='+grade+'&deadline='+deadline+'&header='+header+'&member='+member+'&desc='+desc,
		data:$('#project-details').serialize(),
		success:function(msg){
			if(msg[0].text=='ok'){alert("修改成功");                /*处理函数，根据后台需要*/
						var tab = $(".easyui-tabs").tabs('getSelected');
			 		$(".easyui-tabs").tabs('update',
			                        {tab:tab,
									 options:{
								     cache:false,
                                     href:'project/teacher/project.jsp',
									 }
									});
			           $('#dd').dialog('refresh','project/teacher/item-details.jsp?row='+msg[0].row);
						 }
			 else{alert("修改失败");}
			  }
			  })
			  }
	   else{
			alert('请补充完整信息');
			return false;}
})
</script>
</body>


